package com.example.bitcoinconverter;



import android.os.Bundle;
import android.os.StrictMode;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Toast;

public class MainActivity extends Activity {
	private EditText value;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		StrictMode.setThreadPolicy(policy);
		setContentView(R.layout.activity_main);
		value = (EditText) findViewById(R.id.value);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	public void onClickConvert(View view) {
		
	    switch (view.getId()) {
	    
	    case R.id.convert:
	    	
	      RadioButton pln = (RadioButton) findViewById(R.id.pln);
	      RadioButton usd = (RadioButton) findViewById(R.id.usd);
	      RadioButton eur = (RadioButton) findViewById(R.id.eur);
	      RadioButton chf = (RadioButton) findViewById(R.id.chf);
	      
	      if (value.getText().length() == 0) {
	        Toast.makeText(this, "Please enter a valid number",Toast.LENGTH_LONG).show();
	        return;
	      }
	      
	      double input = Double.parseDouble(value.getText().toString());
	      double result = 0;
	      String currency = "EUR";
	      
	      if (pln.isChecked()) currency = "PLN";
	      if (eur.isChecked()) currency = "EUR";
	      if (usd.isChecked()) currency = "USD";
	      if (chf.isChecked()) currency = "CHF";
	    	 
	      result = CurrencyDownloader.readValue(currency, input);
	      value.setText(String.valueOf(result));

	      break;
	    }
	}
/*
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		Toast.makeText(this, "On Destroy!",Toast.LENGTH_LONG).show();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
		Toast.makeText(this, "On Pause!",Toast.LENGTH_LONG).show();
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
		Toast.makeText(this, "On Restart!",Toast.LENGTH_LONG).show();
	}

	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onRestoreInstanceState(savedInstanceState);
		Toast.makeText(this, "On RestoreSaved...!",Toast.LENGTH_LONG).show();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		Toast.makeText(this, "On Resume!",Toast.LENGTH_LONG).show();
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		Toast.makeText(this, "On Start!",Toast.LENGTH_LONG).show();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		Toast.makeText(this, "On Stop!",Toast.LENGTH_LONG).show();
	}
*/
}
